home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1136 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.0 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: "Nathan Myers <http://www.cantrip.org/>" <ncm@cantrip.org>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Better template syntax?
  5. Date: 17 Apr 1996 10:41:31 PDT
  6. Organization: Best Internet Communications
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <31747848.714640D9@cantrip.org>
  9. References: <31741E6C.53CA@cs.tu-berlin.de>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Tue, 16 Apr 1996 21:49:12 -0700
  12. X-Mailer: Mozilla 2.01 (X11; I; Linux 1.2.13 i386)
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMXUtTUy4NqrwXLNJAQHmxgIAkdvEShLBXsvfDnioe/sZ7yJEuOi39Uex
  15.     jWWaAU4PLM/zJ7XZqRNVZJ5o5Ueg0OX/D+1UpH3Xfwx9p88drIQMLA==
  16.     =EUPK
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. Roman Lechtchinsky wrote:
  20.  
  21. > ... when declaring templates, why isn't it required to declare what 
  22. > one expects of the template's parameters? 
  23. > ... has [this] been considered and rejected ( and why ) ?
  24.  
  25. [This is from a paper by Koenig and Stroustrup, "Foundations for
  26. Native C++ Styles" that appeared in Software Practice and Experience
  27. vol. 25, December '95 (a Wiley pub.).  I encourage readers of this
  28. newsgroup to look it up.] 
  29.  
  30. [I hope my excerpting hasn't done too much damage.]
  31.  
  32. ----------------
  33.  
  34. What does C++ offer no such facility?   There are three main reasons:
  35.  
  36. [1] Any such facility would have to take into account not only inheritance
  37.   but also built-in types and operations on types not defined as members.
  38.   ... Ordinary pointers meet the requirements for random-access iterators
  39.   when they are used to point to elements of (built-in) arrays.  That means
  40.   we would need some way of saying that for any type T, T* is a random-
  41.   access iterator, ... [or] forego the ability to use ... [template] 
  42.   functions on arrays. ...
  43.  
  44. [2] The facility would offer little additional safety, if any.  The main
  45.   benefit would be that errors would be detected when a template function
  46.   ... is called, rather than when code is generated for it... [this is]
  47.   not enough to justify a whole new type-checking facility.
  48.  
  49. [3] Even if such a facility existed ... that would still not guarantee 
  50.   safety. ... Specifying "the expected operations" can be messy and 
  51.   constraining; specifying "the expected semantics" can be surprisingly 
  52.   difficult. ...
  53.  
  54. In general, we know of no way of expressing constraints on template
  55. parameters that wouldn't be either too cumbersome or too constraining.
  56. ...
  57.  
  58. -----------------
  59.  
  60. [In short, any such apparatus (in C++, at least) would be complicated,
  61. over-restrictive, and would fail to do the job required of it.  Some 
  62. incompatible successor to C++ might be designed with such an apparatus
  63. in mind, but today that's a research topic.]
  64.  
  65. Nathan Myers
  66. ncm@cantrip.org  http://www.cantrip.org/
  67. ---
  68. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  69.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  70.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  71.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  72.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  73. ]
  74.